<?php
class CDatabase
{
	
	var $DBName;
	var $DBHost;
	var $DBLogin;
	var $DBPassword;
	var $bConnected;

	public function __construct()
	{

	}
	
	function Connect($DBHost, $DBName, $DBLogin, $DBPassword)
	{
		$this->type="MYSQL";
		$this->DBHost = $DBHost;
		$this->DBName = $DBName;
		$this->DBLogin = $DBLogin;
		$this->DBPassword = $DBPassword;
		$this->bConnected = false;
		
		if (!defined("DBPersistent"))
			define("DBPersistent",true);

		if(defined("DELAY_DB_CONNECT") && DELAY_DB_CONNECT===true)
			return true;
		else
			return $this->DoConnect();
	}
	
	function DoConnect()
	{
		//if($this->bConnected)
			//return;
		//$this->bConnected = true;

		if (DBPersistent)
			$this->db_Conn = mysql_pconnect($this->DBHost, $this->DBLogin, $this->DBPassword);
		else
			$this->db_Conn = mysql_connect($this->DBHost, $this->DBLogin, $this->DBPassword, true);
	}
	
	function Query($sql) {
		global $DB;

		$this->DoConnect();
		$this->db_Error="";
		$result = @mysql_query($sql, $this->db_Conn);
		if(!$result)
		{
			$this->db_Error = mysql_error($this->db_Conn);
			$this->db_ErrorSQL = $sql;
			return false;
		}
		return $result;
	}

}
